import request from '@/utils/request'
import { AxiosPromise } from 'axios'

// apiUrl 字典管理
const api = {
	page: '/sys/dict/page',
	listParent: '/sys/dict/list-parent',
	listSelectOption: '/sys/dict/list-select-options',
	create: '/sys/dict/create',
	update: '/sys/dict/update',
	delete: '/sys/dict/delete'
}
/**
 * 字典管理  - 列表
 */
function dictPageApi(data: any): AxiosPromise {
	return request({
		url: api.page,
		method: 'post',
		data
	})
}

function dictListParentApi(): AxiosPromise {
	return request({
		url: api.listParent,
		method: 'get'
	})
}

// 通过字典编码查询表单下拉选择项列表
function dictListSelectOptionApi(code: string): AxiosPromise {
	return request({
		url: `${api.listSelectOption}?code=${code}`,
		method: 'get'
	})
}

/**
 * 字典管理  - 新增编辑保存
 */
function dictAddOrEditSaveApi(data: any): AxiosPromise {
	return request({
		url: data.id ? api.update : api.create,
		method: 'post',
		data
	})
}

/**
 * 字典管理  - 删除
 */
function dictDeleteApi(data: any): AxiosPromise {
	return request({
		url: api.delete,
		method: 'post',
		data
	})
}
export default {
	dictPageApi,
	dictListParentApi,
	dictListSelectOptionApi,
	dictAddOrEditSaveApi,
	dictDeleteApi
}
